﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.DBUtility;
using System.Data;
using System.Web.Script.Serialization;
namespace SkWeb.RiskDB
{
    public partial class CreateRiskDB : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        [System.Web.Services.WebMethod]
        public static string genId()
        {
            DataTable dt = DbHelperOra.Query("select seq_riskid.nextval from dual").Tables[0];
            return dt.Rows[0][0].ToString();
        }
        [System.Web.Services.WebMethod]
        public static string updateNode(string nodeData, string pCname,string Tname)
        {
            try
            {
                JavaScriptSerializer json_serializer = new JavaScriptSerializer();
                Node node =
                       (Node)json_serializer.DeserializeObject(nodeData);
                string strSql = "select id from risk_table where id ="+node.id+"";
                DataTable dt = DbHelperOra.Query(strSql).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    strSql = "update risk_table set TNAME=" + Tname + ",CNAME=" + pCname + ",DESCRIBE=" + node.Describe + ",VSTART=" + node.Start + ",VEND=" 
                        + node.End + ",NLEVEL=" + node.Level + ",ID=" + node.id ;
                }
                else
                {
                    strSql = "insert into risk_table(TNAME,CNAME,DESCRIBE,VSTART,VEND,NLEVEL,ID)  values(" 
                        + Tname + "," + pCname + "," + node.Describe + "," + node.Start + "," + node.End + "," + node.Level + "," + node.id + ") ";
                }
                DbHelperOra.ExecuteSql(strSql);
            }
            catch(Exception ex)
            {
               string s = ex.Message;
               
            }
            return "OK";
        }
    
    }
    //{"id":1000,"Name":"中等危险","Type":"","Precision":"","Start":"1","End":"20","
    //Level":"2","Describe":"","_parentId":6,"state":"open"}


    //"{\"id\":1000,\"Name\":\"中等危险1\",\"Type\":\"\",\"Precision\":\"\",\"Start\":\"1\",
    //\"End\":\"20\",\"Level\":\"2\",\"Describe\":\"\",\"_parentId\":6,\"state\":\"open\"}"
    public class Node
    {

       int id_;
       string Name_;
       string Type_;
       string Precision_;
       string Start_;
       string End_;
       string Level_;
       string Describe_;
       int _parentId_;
       string state_;

      public   int id
      {
          get { return id_; }
          set {id_ = value; }
      }
      public string Name
      {
          get { return Name_; }
            set { Name_ = value; }
      }
      public string Type
           {
               get { return Type_; }
               set { Type_ = value; }
      }
      public string Precision
           {
               get { return Precision_; }
               set { Precision_ = value; }
      }
      public string Start
           {
               get { return Start_; }
               set { Start_ = value; }
      }
      public string End
           {
               get { return End_; }
               set { End_ = value; }
      }
      public string Level
           {
               get { return Level_; }
               set { Level_ = value; }
      }
      public string Describe
           {
               get { return Describe_; }
               set { Describe_ = value; }
      }
      public int _parentId
           {
               get { return _parentId_; }
               set { _parentId_ = value; }
      }
      public string state
      {
          get { return state_; }
          set { state_ = value; }
      }
    }
}